//-----------------------------------------------------------------------------------------------------------------
//  Version | DateTime(Create Or Update)  |  UserName		              |  Description						                  |
//-----------------------------------------------------------------------------------------------------------------
//  1.0		  | 2025/08/01 15:39:50		      | WEI.ZHOU (Willis)	        |  Create FormMain.cs Class
//-----------------------------------------------------------------------------------------------------------------

using Common.Framework.Launcher.Utils;
using System;
using System.Drawing;
using System.IO;
using System.Windows.Forms;

// ReSharper disable LocalizableElement
namespace Common.Framework.Launcher
{
  /// <summary>
  /// 启动主窗口
  /// </summary>
  public sealed partial class FormMain : Form
  {

    /// <summary>
    /// 启动配置文件
    /// </summary>
    private static readonly INIHelper iniHelper =
      new INIHelper(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Launcher.ini"));

    /// <summary>
    /// 启动程序名称
    /// </summary>
    private readonly string sLauncherAppName;

    /// <summary>
    /// 启动程序版本
    /// </summary>
    private readonly string sLauncherAppVersion;

    /// <summary>
    /// 启动程序名称
    /// </summary>
    private readonly string sAppName;

    /// <summary>
    /// 启动程序版本
    /// </summary>
    public FormMain()
    {
      InitializeComponent();
      this.DoubleBuffered = true;

      sAppName = iniHelper.Read("AppMainSetting", "AppMainName", "Common.Framework.Launcher");
      sLauncherAppName = iniHelper.Read("LauncherSetting", "LauncherAppName", "Common.Framework.Launcher");
      sLauncherAppVersion = iniHelper.Read("LauncherSetting", "LauncherAppVersion", "1.8.0.0");
    }

    /// <summary>
    /// 启动窗口初始化
    /// </summary>
    public void FormMainInit()
    {
      this.BackColor = Color.Transparent;
      this.labelAppTitle.Text = sAppName;
    }

    /// <summary>
    /// 进度条定时器
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void timerPargressbar_Tick(object sender, EventArgs e)
    {
      panelProgressbar.Width += 5;

      if (panelProgressbar.Width < 100)
      {
        labelInitConfig.Text = "Initiator loads default configuration file...";
      }
      else if (panelProgressbar.Width < 200)
      {
        labelInitConfig.Text = "Initiator loads core configuration file...";
      }
      else if (panelProgressbar.Width < 300)
      {
        labelInitConfig.Text = "Initiator loads default data file...";
      }
      else if (panelProgressbar.Width < 500)
      {
        labelInitConfig.Text = "Complete loading of all files...";
      }
      else
      {
        labelInitConfig.Text = $"Start Startup App [{sLauncherAppName}] {sLauncherAppVersion} ...";
      }

      if (panelProgressbar.Width >= 700)
      {
        timerPargressbar.Stop();
        this.DialogResult = DialogResult.OK;
      }
    }
  }
}